<!-- 客户渠道分配 客户列表组件 -->
<template>
  <div>
    <div>
      <el-form :inline="true"  class="demo-form-inline">
      
        <el-form-item label="销售员">
          <el-select v-model="selectAdmin" placeholder="销售员">
            <el-option :label="item.ADMIN_NAME" :value="item.ADMIN_ID" :key="item.ADMIN_ID" v-for="item in userList"></el-option>         
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">分配</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="space20">
    </div>
    <el-table ref="multipleTable" :data="tableData3" border tooltip-effect="dark" style="width: 100%" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column prop="CUSTOM_ID" label="客户编号" width="180">
      </el-table-column>
      <el-table-column prop="CUSTOM_NAME" label="客户名称" width="100">
      </el-table-column>
      <el-table-column prop="CUSTOM_BIRTHDATE" label="出生日期" width="180">
      </el-table-column>
      <el-table-column prop="CUSTOM_COUNTRY" label="留学国家" width="100">
      </el-table-column>
      <el-table-column prop="CUSTOM_SCHOOL" label="留学目的地国家/地区教育机构名称" width="200">
      </el-table-column>
      <el-table-column prop="CUSTOM_EMAIL" label="电子邮箱" width="200">
      </el-table-column>
      <el-table-column prop="CUSTOM_PRODUCE" label="推荐套餐" width="200">
      </el-table-column>
      <el-table-column prop="CUSTOM_LEVEL" label="客户等级" width="200">
      </el-table-column>
       <el-table-column prop="ADMIN_NAME" label="客户负责人" width="200">
      </el-table-column>
     

    </el-table>
    <div class="block">
      <el-pagination @current-change="handleCurrentChange" :current-page="currentPage1" :page-size="10" layout="total, prev, pager, next" :total="pagecount">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import api from "@/js/api";
export default {
  data() {
    return {
      selectAdmin: "",
      pagecount: 0,
      currentPage1: 0,
      tableData3: [],
      multipleSelection: []
    };
  },
  props: {
    userList: {
      type: Array,
      default: []
    }
  },
  methods: {
    handleCurrentChange(val) {
      // console.log(val);
      this.currentPage = val;
      this.Getdata();
    },
    onSubmit() {
      if (this.multipleSelection.length == 0) {
        this.$notify.error({
          title: "失败",
          message: "请选择客户"
        });
        return;
      }
      if(this.selectAdmin==""){
         this.$notify.error({
          title: "失败",
          message: "请选择销售员"
        });
        return;
      }
      var arryList = [];
      for (let i = 0; i < this.multipleSelection.length; i++) {
        arryList.push(this.multipleSelection[i].CUSTOM_ID);
      }
      let that = this;
      let data = {
        AdminId: this.selectAdmin,
        List: arryList
      };
      api.ChangeCustomUser(that, data);
    },
    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    //获取数据
    Getdata() {
      let that = this;
      var data = {
        pageIndex: this.currentPage,
        pageSize: 10
      };
      api.GetNoOrganzationList(that, data, function(msg) {
        that.tableData3 = msg.Result;
        that.pagecount = msg.ListCount;
      });
    }
  },
  created() {
    this.currentPage = 1;
    this.Getdata();
  }
};
</script>